package com.brush.brushsysapi.controller;


import com.brush.brushcommon.common.sys.pojo.User;
import com.brush.brushcommon.common.sys.service.UserService;
import com.brush.brushcommon.dto.Result;
import com.brush.brushcommon.utils.JwtHelper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@Tag(name = "用户接口")
@RestController
@RequestMapping("/users")
public class UserController {

    @Resource
    private UserService userService;



    @Operation(summary = "获取当前登录用户信息")
    @GetMapping("/me")
    public Result getCurrentUser(@RequestHeader("Authorization") String token) {
//        TODO 展示从数据库获取用户信息 后期改为redis
        token=token.split(" ")[1];
        String userId = JwtHelper.getUserId(token);
        User user = userService.getById(userId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("avatar",user.getVxAvatar());
        map.put("nickname",user.getUsername());
        map.put("userId",userId);
        map.put("username",user.getUsername());
//        跟前端这个参数干嘛的 目前先设置为空
        map.put("perms", Collections.emptyList());
        map.put("roles",new ArrayList<String>().add("ADMIN"));
        return Result.success(map);
    }


}
